#include "stdio.h"
#include "string.h"
#include "math.h"
int cmp(const void *a,const void *b){
    int a1 = *((int *)a);
    int b1 = *((int *)b);
    return a1-b1;
}


int main(){
    int n=0;
    int num=0;
    int all_num[10001]={0};
    int all_num_copy[10001] = {0};
    scanf("%d",&n);
    for (int i = 0; i < n; ++i) {
        scanf("%d",&all_num[i]);
        all_num_copy[i]=all_num[i];
    }
    qsort(all_num_copy,n,sizeof (all_num_copy[0]),cmp);
    for (int i = 0; i < n; ++i) {
        num = all_num[i];
        while (num!=1){
            if(num%2==0){
                num = num/2;
                for (int j = 0; j < n; ++j) {
                    if(all_num_copy[j]==num){
                        all_num_copy[j]=0;
                    }
                }
            } else{
                num = (3*num+1)/2;
                for (int j = 0; j < n; ++j) {
                    if (all_num_copy[j]==num){
                        all_num_copy[j]=0;
                    }
                }
            }
        }
    }
    int i=0,j=0;
    while (i<n){
        if(all_num_copy[i]!=0){
            all_num_copy[j++]=all_num_copy[i];
        }
        i++;
    }
    for(int k=j-1;k>0;k--){
        printf("%d ",all_num_copy[k]);
    }
    printf("%d",all_num_copy[0]);
    return 0;
}













